package org.example.user.manage.controller;

import org.example.commons.vo.ResultVO;
import org.example.user.manage.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * author 陈伯瑞
 * date 2020/6/15 0015 18:17
 * version 1.0
 **/
@RestController
@RequestMapping("/api/user/data")
public class UserDataAnalysis {
    /**
     *用户数据分析
     *
     */
    @Autowired
    private ISysUserService sysUserService;
    /* 返回所有的用户数量*/
    @GetMapping("/num")
    public ResultVO analysis()  {
     return  ResultVO.success(sysUserService.queryAll().size());
    }

   /* 返回最近天数的用户数量*/
    @GetMapping("/ByDay")
    public Number dataByDay(@RequestParam("days") Integer days) {
        return  sysUserService.queryLastUserBydays(days).size();
    }

    /*返回最近三十天和上个三十天的数据*/
    @GetMapping("/Bymonth")
    public ResultVO dataBymonth() {
        Map map=new HashMap();
        List<Integer> data = new ArrayList<Integer>();
        data.add(sysUserService.queryLastUserBydays(24).size());
        data.add(sysUserService.queryLastUserBydays(18).size());
        data.add(sysUserService.queryLastUserBydays(12).size());
        data.add(sysUserService.queryLastUserBydays(6).size());
        data.add(sysUserService.queryLastUserBydays(0).size());
        map.put("newData",data);

        List<Integer> datal = new ArrayList<Integer>();
        datal.add(sysUserService.queryLastUserBydays(49).size());
        datal.add(sysUserService.queryLastUserBydays(43).size());
        datal.add(sysUserService.queryLastUserBydays(37).size());
        datal.add(sysUserService.queryLastUserBydays(31).size());
        datal.add(sysUserService.queryLastUserBydays(25).size());
        map.put("oldData",datal);
        return ResultVO.success(map);
    }


}
